using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;

namespace ArchSoft
{
    public partial class SynchronizeTextCaseFrm : Form
    {
        Thread myth = null;
        ProgressingWin fr = null;
        string TxCase = "S";

        public SynchronizeTextCaseFrm()
        {
            InitializeComponent();
        }

        #region " Propertiese "

        string ProjectPath_ = "";
        public string projectPath
        {
            set { this.ProjectPath_ = value; }
        }

        #endregion
        
        private void button1_Click(object sender, EventArgs e)
        {           
            foreach(RadioButton rb in this.panelEx1.Controls )
                if (rb.Checked)
                {
                    TxCase = rb.Tag.ToString();
                    break;
                }

            myth = new Thread(ChangeTextCaseAllDrawingMain);
            myth.IsBackground = true;
            fr = new ProgressingWin(myth);
            fr.MessText = "Synchronize Textcase successfully.";
            fr.Text = "Synchronize Textcase";
            this.Opacity = 0;
            //this.ShowInTaskbar = false;
            fr.ShowDialog();
            Close();
        }

        public void ChangeTextCaseAllDrawingMain()
        {
            string sourcePath = this.ProjectPath_ + Path.DirectorySeparatorChar + ProjectManager.PROJECT_OUTPUT_FOLDER;
            string Tempfl = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Trang\\" + ProjectManager.DEFAULT_APP_NAME + "\\Text.dwg";
            SynchronizeTextCase binder = new SynchronizeTextCase(sourcePath, TxCase, Tempfl);
            binder.Process();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}

#region " Extra Codes  "

/*
 * if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Trang\\" + ProjectManager.DEFAULT_APP_NAME + "\\Annotation Block\\AnnoBlockRegs.abr"))
            {
                File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Trang\\" + ProjectManager.DEFAULT_APP_NAME + "\\Annotation Block\\AnnoBlockRegs.abr");
            }

            StreamReader sr = new StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Trang\\" + ProjectManager.DEFAULT_APP_NAME + "\\Annotation Block\\Annotation Block.txt");
            StreamWriter sw = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Trang\\" + ProjectManager.DEFAULT_APP_NAME + "\\Annotation Block\\AnnoBlockRegs.abr");

            string dta = "";
            while (true)
            {
                try
                {
                 dta =    sr.ReadLine();
                 if (dta != "")
                     sw.WriteLine(EncodeDecode.GetEncoded(dta));

                    if (sr.EndOfStream)
                        break;

                }
                catch { break; }
            }
            sr.Close();
            sw.Close();
 */

#endregion